package com.cym.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cym.service.DatabaseService;
import com.cym.utils.BaseController;
import com.cym.utils.JsonResult;
import com.cym.utils.SqlChanger;

import cn.hutool.core.util.StrUtil;

@Controller
@RequestMapping("/createChanger")
public class CreateChangerController extends BaseController {

	@Autowired
	DatabaseService databaseService;

	@RequestMapping("")
	public ModelAndView main(ModelAndView modelAndView) {
		modelAndView.setViewName("/createChanger/index");
		return modelAndView;
	}

	@ResponseBody
	@RequestMapping("/build")
	public JsonResult getCode(String oldSql, String view, String schemaName) {
		String newSql = SqlChanger.change(oldSql, view, schemaName);
		String otherSql = SqlChanger.other(oldSql, view, schemaName);
		
		Map<String, String> map = new HashMap<String, String>();
		map.put("newSql", newSql);
		map.put("otherSql", otherSql);
		
		return renderSuccess(map);
	}

}
